//
//  GroupInfoViewController.m
//  MemberProject
//
//  Created by mac on 15/7/8.
//  Copyright (c) 2015年 MAC OS X. All rights reserved.
//

#import "GroupInfoViewController.h"
#import "InfoTableViewCell.h"
@interface GroupInfoViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic)UITableView *tableView;
@property(strong,nonatomic)NSArray *data;
@end

@implementation GroupInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title=@"志愿者团体信息";
    
    NSMutableArray *arrM=[NSMutableArray array];
    [arrM addObjectsFromArray:@[@{@"key":@"团体代码:",@"name":self.groupCode},@{@"key":@"团体名称:",@"name":self.resultDic[@"groupName"]},@{@"key":@"地址:",@"name":self.resultDic[@"groupAddress"]}]];
    NSString *orgName=self.resultDic[@"orgName"];
    if(![orgName isKindOfClass:[NSNull class]]&&orgName.length!=0){
        [arrM addObject:@{@"所属团组织":@"",@"orgName":orgName}];
    }
    self.data=arrM;
    
//    self.edgesForExtendedLayout = UIRectEdgeNone;
//    self.automaticallyAdjustsScrollViewInsets=NO;
    
    float height=[Utils heightForLabel:[self.data lastObject][@"name"] andFont:17.0f andWidth:SCREEN_WIDTH-100-12-8-10];
    if(height<50){
        height=50;
    }
    
    UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    [self.view addSubview:tableView];
    tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    tableView.delegate=self;
    tableView.dataSource=self;
    self.tableView=tableView;
    
//    tableView.scrollEnabled=NO;
//    tableView.layer.cornerRadius=5.0f;
//    tableView.layer.borderWidth=0.5;
//    tableView.layer.borderColor=[UIColor colorWithRed:231/255.0 green:231/255.0 blue:231/255.0 alpha:1].CGColor;
    
    [tableView registerNib:[UINib nibWithNibName:@"InfoTableViewCell" bundle:nil] forCellReuseIdentifier:@"CellIdentifier"];
    
    UIView *footerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20)];
    tableView.tableFooterView=footerView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier=@"CellIdentifier";
    InfoTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    NSDictionary *dic=self.data[indexPath.row];
    cell.keyLabel.text=dic[@"key"];
    cell.nameLabel.text=dic[@"name"];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row==self.data.count-1){
        float height=[Utils heightForLabel:self.data[indexPath.row][@"name"] andFont:17.0f andWidth:SCREEN_WIDTH-100-12-8];
        if(height>50){
            return height;
        }else{
            return 50;
        }
    }
    return 50;
}

@end
